package com.yh.modules.data.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.yh.common.annotation.SysLog;
import com.yh.common.constant.StatusEnums;
import com.yh.common.utils.PageUtils;
import com.yh.common.utils.R;
import com.yh.common.utils.ValidatorUtils;
import com.yh.modules.data.entity.MachineEntity;
import com.yh.modules.data.service.MachineService;
import com.yh.shiro.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 机器表
 */
@RestController
@RequestMapping("/machine")
public class MachineController {

	@Autowired
	private MachineService machineService;

	/**
	 * 列表(用户)
	 */
	@GetMapping("/list")
	@RequiresPermissions("data:machine:list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = machineService.queryPage(params);

		return R.ok().put("page", page);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("data:machine:info")
	public R info(@PathVariable("id") Integer id) {
		MachineEntity machine = machineService.selectById(id);

		return R.ok().put("machine", machine);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("data:machine:save")
	@SysLog("新增机器")
	public R save(@RequestBody MachineEntity machine) {
		ValidatorUtils.validateEntity(machine);

		machineService.save(machine);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("data:machine:update")
	@SysLog("修改机器")
	public R update(@RequestBody MachineEntity machine) {
		ValidatorUtils.validateEntity(machine);
		machineService.update(machine);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("data:machine:delete")
	@SysLog("删除机器")
	public R delete(@RequestBody Integer[] ids) {
		machineService.deleteBatchIds(Arrays.asList(ids));

		return R.ok();
	}

}
